package android.cs2340UDT;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.TextView;
import android.app.Activity;
;

public class ItemViewActivity extends Activity {
	
	Manager manage = Security.getManager();
	private Item currentItem;
	
	
	 /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.item_view);
    
        ImageButton BackButton = (ImageButton) findViewById(R.id.Back);
        ImageButton SettingsButton = (ImageButton) findViewById(R.id.Settings);
        ImageButton AddButton = (ImageButton) findViewById(R.id.Add);
        
        Button MapButton = (Button) findViewById(R.id.Map);
        Button ListsButton = (Button) findViewById(R.id.Lists);
        Button CalButton = (Button) findViewById(R.id.Cal);
        
        // Getting all the text view objects to input text into
        TextView itemName = (TextView) findViewById(R.id.textView2);
        TextView timeDue = (TextView) findViewById(R.id.TextView04);
        TextView alertTime = (TextView) findViewById(R.id.TextView02);
        TextView taskComment = (TextView) findViewById(R.id.textView3);
        
        CheckBox completedButton = (CheckBox) findViewById(R.id.completed);
        
        // getting the current item in use
        currentItem = manage.getCurrentItem();
        
        completedButton.setChecked(currentItem.getComplete());
        
        // setting all the UI text view's to the current item's info
        itemName.setText(currentItem.getDescription());
        //timeDue.setText(currentItem.getFormattedDueDate());
        timeDue.setText(currentItem.getDueDate());
        if(currentItem.getComplete()) {
        	alertTime.setText("Complete " + manage.getCurrentItemList().sortString);
        }
        else { 
        	alertTime.setText("Not Complete");
        }
        taskComment.setText(currentItem.getComment());
        
        completedButton.setOnCheckedChangeListener(new OnCheckedChangeListener()
        {
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
            {
                currentItem.setComplete(isChecked);
            }
        });
    
        //Listening to Register Add item Button button event
        AddButton.setOnClickListener(new View.OnClickListener() {

        	public void onClick(View arg0) {
        		//Starting a new Intent
        		Intent nextScreen = new Intent(getApplicationContext(), CreateItemActivity.class);
        		finish();
        		//Switches over to CreateItemActivity
        		startActivity(nextScreen);

        	}
        });
        
        BackButton.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View arg0)
        	{
        		Intent nextScreen = new Intent(getApplicationContext(), ListViewActivity.class);
        		finish();
        		startActivity(nextScreen);
        	}
			
		});
        
        SettingsButton.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View arg0)
        	{
        		Intent nextScreen = new Intent(getApplicationContext(), MainScreenActivity.class);
        		finish();
        		startActivity(nextScreen);
        	}
			
		});
        
        MapButton.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View arg0)
        	{
        		Intent nextScreen = new Intent(getApplicationContext(), MapScreenActivity.class);
        		startActivity(nextScreen);
        	}
			
		});
        
        ListsButton.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View arg0)
        	{
        		Intent nextScreen = new Intent(getApplicationContext(), MainScreenActivity.class);
        		finish();
        		// startActivity(nextScreen);
        	}
			
		});
        
        CalButton.setOnClickListener(new View.OnClickListener() {
        	
        	public void onClick(View arg0)
        	{
        		Intent nextScreen = new Intent(getApplicationContext(), MainScreenActivity.class);
        		finish();
        		// startActivity(nextScreen);
        	}
			
		});
    }
}